package models;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.OneToMany;

import org.codehaus.jackson.annotate.JsonIgnore;
import org.hibernate.validator.constraints.NotBlank;

import play.data.validation.Constraints.Required;
import play.db.ebean.Model;

@Entity
public class User extends Model {

    private static final long serialVersionUID = 1L;

    @Id
    private Long id;

    @NotBlank(message = "Username cannot be blank")
    @Required(message = "An username is required")
    private String username;

    @JsonIgnore
    @NotBlank(message = "Password cannot be blank")
    @Required(message = "A password is required")
    private String password;

    private boolean isAdmin;

    @JsonIgnore
    @OneToMany(mappedBy = "user")
    private List<Event> listEvent;

    public List<Event> getListEvent() {
        return listEvent;
    }

    public void setListEvent(List<Event> listEvent) {
        this.listEvent = listEvent;
    }

    @JsonIgnore
    @OneToMany(mappedBy = "user", cascade = CascadeType.ALL)
    private List<ApiKey> apiAccess;

    public static Finder<Long, User> find = new Finder<Long, User>(Long.class, User.class);

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public static Finder<Long, User> getFind() {
        return find;
    }

    public static void setFind(Finder<Long, User> find) {
        User.find = find;
    }

    public List<ApiKey> getApiAccess() {
        return apiAccess;
    }

    public void setApiAccess(List<ApiKey> apiAccess) {
        this.apiAccess = apiAccess;
    }

    public boolean isAdmin() {
        return isAdmin;
    }

    public void setAdmin(boolean isAdmin) {
        this.isAdmin = isAdmin;
    }
}
